import 'package:flutter/material.dart';
import 'package:flutterhello/controller/ChatController.dart';
import 'package:flutterhello/pages/four/four.dart';
import 'package:flutterhello/pages/one/one.dart';
import 'package:flutterhello/pages/three/three.dart';
import 'package:flutterhello/pages/two/two.dart';
import 'package:get/get.dart';

import 'controller/Controller.dart';
import 'controller/overall.dart';

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<Widget> pages = [OnePage(), TwoPage(), ThreePage(), FourPage()];
  final controller = Get.put(Controller());
  var pageController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    pageController =
        PageController(initialPage: controller.selectedIndex.value);
  }

  @override
  Widget build(BuildContext context) {
    Get.put(OverAll());
    return Obx(
      () => Scaffold(
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: controller.selectedIndex.toInt(),
          fixedColor: Colors.blueGrey,
          onTap: (index) {
            pageController.jumpToPage(index);
          },
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.home,
                  size: 25,
                ),
                label: '一'),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: '二'),
            BottomNavigationBarItem(icon: Icon(Icons.info), label: '三'),
            BottomNavigationBarItem(
                icon: Icon(Icons.account_circle), label: '我的')
          ],
        ),
        body: PageView(
          controller: pageController,
          children: pages,
          physics: NeverScrollableScrollPhysics(),
          onPageChanged: controller.onItemTapped,
        ),
      ),
    );
  }
}
//pages[controller.selectedIndex.toInt()]
